Skip to content

Conversation

@sgasho
Copy link
Contributor

@sgasho sgasho commented Nov 24, 2025

related issue: #145899
related pr: #146623

This PR is a continuation of #146623

I refactored some code for #146623 and added the functions shown in #144197

r? @bjorn3
cc: @ZuseZ4

Zulip link: https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/libload.20.2F.20dlopen.20Enzyme.2Fautodiff/near/553647912

@rustbot
Copy link
Collaborator

rustbot commented Nov 24, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

cc @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 24, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

That's exciting, and is gonna make some people on the infra team very happy. Just to be sure, are the tests still passing?

@rust-log-analyzer

This comment has been minimized.

let attr_name = "enzyme_type";
let c_attr_name = CString::new(attr_name).unwrap();

let enzyme_wrapper = EnzymeWrapper::get_instance().lock().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return a MutexGuard from EnzymeWrapper::get_instance()?

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
fn enable_autodiff_settings(cgcx: &CodegenContext<LlvmCodegenBackend>, ad: &[config::AutoDiff]) {
use std::sync::Mutex;
let enzyme: &'static Mutex<llvm::EnzymeWrapper> = llvm::EnzymeWrapper::init(cgcx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe return a MutexGuard from EnzymeWrapper::init()?

}

fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
fn enable_autodiff_settings(cgcx: &CodegenContext<LlvmCodegenBackend>, ad: &[config::AutoDiff]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this from LlvmCodegenBackend::init() instead? There you have access to the full Session.

@sgasho
Copy link
Contributor Author

sgasho commented Nov 24, 2025

(oops, sorry I should have run tests before opening this pr. It takes too much time running tests on my m1 mac so let me check them tomorrow, including ci failures..... 🙇)

@bjorn3
Copy link
Member

bjorn3 commented Nov 24, 2025

Don't worry. I don't run all tests either before opening a PR either, that indeed takes way too long. I mostly run ./x.py check or ./x.py test path/to/relevant/tests + if I remember ./x.py test src/tools/tidy.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

Oh sorry, I was only referring to all the autodiff tests mentioned here. I'm also not running all tests.
Also just building it on my laptop, but it needs a new LLVM version and that always takes a while.

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 24, 2025

@sgasho It seems that all autodiff tests invoking enzyme fail, e.g:

thread 'rustc' (2936300) panicked at compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:211:35:
EnzymeWrapper not initialized
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::option::expect_failed
   3: rustc_codegen_llvm::typetree::add_tt
   4: rustc_codegen_llvm::intrinsic::codegen_autodiff
failures:
    [codegen] tests/codegen-llvm/autodiff/trait.rs
    [codegen] tests/codegen-llvm/autodiff/identical_fnc.rs
    [codegen] tests/codegen-llvm/autodiff/typetree.rs
    [codegen] tests/codegen-llvm/autodiff/generic.rs
    [codegen] tests/codegen-llvm/autodiff/abi_handling.rs#release
    [codegen] tests/codegen-llvm/autodiff/batched.rs
    [codegen] tests/codegen-llvm/autodiff/autodiffv2.rs

I still remember I had the same issue in my original PR, so that might be the reason.

…or_init takes only sysroot, not a whole session or context
@rustbot
Copy link
Collaborator

rustbot commented Nov 25, 2025

Some changes occurred in compiler/rustc_codegen_llvm/src/builder/autodiff.rs

cc @ZuseZ4

@sgasho
Copy link
Contributor Author

sgasho commented Nov 25, 2025

thread 'rustc' (2936300) panicked at compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:211:35:
EnzymeWrapper not initialized

I solved the "EnzymeWrapper not initialized" problem in the latest commit (52f0d2e)

However, another error occurred

e.g.

./x test --stage 1 tests/codegen-llvm/autodiff/scalar.rs
Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.14s
WARNING: The `change-id` is missing in the `bootstrap.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.
NOTE: to silence this warning, add `change-id = 148803` or `change-id = "ignore"` at the top of `bootstrap.toml`
Building stage1 compiler artifacts (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.55s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage1 wasm-component-ld (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.59s
Building stage1 llvm-bitcode-linker (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.12s
Building stage1 library artifacts (stage1 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 0.25s
Building stage1 compiletest (stage0 -> stage1, aarch64-apple-darwin)
    Finished `release` profile [optimized] target(s) in 2.77s
Testing stage1 with compiletest suite=codegen-llvm mode=codegen (aarch64-apple-darwin)

running 1 tests

[codegen] tests/codegen-llvm/autodiff/scalar.rs ... F


failures:

---- [codegen] tests/codegen-llvm/autodiff/scalar.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
Assertion failed: (AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"), function getResult, file PassManager.h, line 414.

------------------------------------------

error: compilation failed!
status: signal: 6 (SIGABRT)
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/stage1/bin/rustc" "/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/tests/codegen-llvm/autodiff/scalar.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Users/suganoshota/.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/vendor" "--sysroot" "/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/stage1" "--target=aarch64-apple-darwin" "--check-cfg" "cfg(test,FALSE)" "-O" "-Cdebug-assertions=no" "-Zcodegen-source-order" "--emit" "llvm-ir" "-o" "/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/test/codegen-llvm/autodiff/scalar/scalar.ll" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Zautodiff=Enable,NoTT" "-C" "opt-level=3" "-Clto=fat"
stdout: none
--- stderr -------------------------------
Assertion failed: (AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"), function getResult, file PassManager.h, line 414.
------------------------------------------

---- [codegen] tests/codegen-llvm/autodiff/scalar.rs stdout end ----

failures:
    [codegen] tests/codegen-llvm/autodiff/scalar.rs

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 964 filtered out; finished in 529.35ms

Some tests failed in compiletest suite=codegen-llvm mode=codegen host=aarch64-apple-darwin target=aarch64-apple-darwin
Build completed unsuccessfully in 0:00:18

I could not figure out what triggers "This analysis pass was not registered prior to being queried". codex cli says Enzyme has a problem but I'm not sure if it's right. I'll take look into it tomorrow.

スクリーンショット 2025-11-25 23 36 10

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] jiff test:false 10.018
[RUSTC-TIMING] rustc_codegen_ssa test:false 16.622
[RUSTC-TIMING] rustc_llvm test:false 0.084
   Compiling rustc_codegen_llvm v0.0.0 (/checkout/compiler/rustc_codegen_llvm)
error[E0599]: no function or associated item named `get_or_init` found for struct `Fallback_AD::EnzymeWrapper` in the current scope
   --> compiler/rustc_codegen_llvm/src/back/lto.rs:534:43
    |
534 |     let mut enzyme = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
    |                                           ^^^^^^^^^^^ function or associated item not found in `Fallback_AD::EnzymeWrapper`
    |
   ::: compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:477:5
    |
477 |     pub(crate) struct EnzymeWrapper {
    |     ------------------------------- function or associated item `get_or_init` not found for this struct
    |
help: there is a method `set_print` with a similar name
    |
534 -     let mut enzyme = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
534 +     let mut enzyme = llvm::EnzymeWrapper::set_print(&cgcx.sysroot);
    |

error[E0599]: no function or associated item named `get_or_init` found for struct `Fallback_AD::EnzymeWrapper` in the current scope
   --> compiler/rustc_codegen_llvm/src/back/write.rs:737:44
    |
737 |         let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
    |                                            ^^^^^^^^^^^ function or associated item not found in `Fallback_AD::EnzymeWrapper`
    |
   ::: compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:477:5
    |
477 |     pub(crate) struct EnzymeWrapper {
    |     ------------------------------- function or associated item `get_or_init` not found for this struct
    |
help: there is a method `set_print` with a similar name
    |
737 -         let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
737 +         let wrapper = llvm::EnzymeWrapper::set_print(&cgcx.sysroot);
    |

error[E0599]: no method named `new_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:599:29
    |
599 |         let inner = wrapper.new_type_tree();
    |                             ^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `new_type_tree_ct` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:605:29
    |
605 |         let inner = wrapper.new_type_tree_ct(t, ctx);
    |                             ^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `merge_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:611:17
    |
611 |         wrapper.merge_type_tree(self.inner, other.inner);
    |                 ^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `shift_indicies_eq` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:626:17
    |
626 |         wrapper.shift_indicies_eq(
    |         --------^^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_insert_eq` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:639:17
    |
639 |         wrapper.tree_insert_eq(self.inner, indices.as_ptr(), indices.len(), ct, ctx);
    |                 ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `new_type_tree_tr` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:646:29
    |
646 |         let inner = wrapper.new_type_tree_tr(self.inner);
    |                             ^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_to_string` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:654:27
    |
654 |         let ptr = wrapper.tree_to_string(self.inner);
    |                           ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_to_string_free` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:662:17
    |
662 |         wrapper.tree_to_string_free(ptr);
    |                 ^^^^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `free_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:677:17
    |
677 |         wrapper.free_type_tree(self.inner)
    |                 ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

For more information about this error, try `rustc --explain E0599`.
[RUSTC-TIMING] rustc_codegen_llvm test:false 2.923
error: could not compile `rustc_codegen_llvm` (lib) due to 11 previous errors
Bootstrap failed while executing `--stage 2 test --skip compiler --skip src`

1 similar comment
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] jiff test:false 10.018
[RUSTC-TIMING] rustc_codegen_ssa test:false 16.622
[RUSTC-TIMING] rustc_llvm test:false 0.084
   Compiling rustc_codegen_llvm v0.0.0 (/checkout/compiler/rustc_codegen_llvm)
error[E0599]: no function or associated item named `get_or_init` found for struct `Fallback_AD::EnzymeWrapper` in the current scope
   --> compiler/rustc_codegen_llvm/src/back/lto.rs:534:43
    |
534 |     let mut enzyme = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
    |                                           ^^^^^^^^^^^ function or associated item not found in `Fallback_AD::EnzymeWrapper`
    |
   ::: compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:477:5
    |
477 |     pub(crate) struct EnzymeWrapper {
    |     ------------------------------- function or associated item `get_or_init` not found for this struct
    |
help: there is a method `set_print` with a similar name
    |
534 -     let mut enzyme = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
534 +     let mut enzyme = llvm::EnzymeWrapper::set_print(&cgcx.sysroot);
    |

error[E0599]: no function or associated item named `get_or_init` found for struct `Fallback_AD::EnzymeWrapper` in the current scope
   --> compiler/rustc_codegen_llvm/src/back/write.rs:737:44
    |
737 |         let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
    |                                            ^^^^^^^^^^^ function or associated item not found in `Fallback_AD::EnzymeWrapper`
    |
   ::: compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:477:5
    |
477 |     pub(crate) struct EnzymeWrapper {
    |     ------------------------------- function or associated item `get_or_init` not found for this struct
    |
help: there is a method `set_print` with a similar name
    |
737 -         let wrapper = llvm::EnzymeWrapper::get_or_init(&cgcx.sysroot);
737 +         let wrapper = llvm::EnzymeWrapper::set_print(&cgcx.sysroot);
    |

error[E0599]: no method named `new_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:599:29
    |
599 |         let inner = wrapper.new_type_tree();
    |                             ^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `new_type_tree_ct` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:605:29
    |
605 |         let inner = wrapper.new_type_tree_ct(t, ctx);
    |                             ^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `merge_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:611:17
    |
611 |         wrapper.merge_type_tree(self.inner, other.inner);
    |                 ^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `shift_indicies_eq` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:626:17
    |
626 |         wrapper.shift_indicies_eq(
    |         --------^^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_insert_eq` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:639:17
    |
639 |         wrapper.tree_insert_eq(self.inner, indices.as_ptr(), indices.len(), ct, ctx);
    |                 ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `new_type_tree_tr` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:646:29
    |
646 |         let inner = wrapper.new_type_tree_tr(self.inner);
    |                             ^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_to_string` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:654:27
    |
654 |         let ptr = wrapper.tree_to_string(self.inner);
    |                           ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `tree_to_string_free` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:662:17
    |
662 |         wrapper.tree_to_string_free(ptr);
    |                 ^^^^^^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

error[E0599]: no method named `free_type_tree` found for reference `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>` in the current scope
   --> compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs:677:17
    |
677 |         wrapper.free_type_tree(self.inner)
    |                 ^^^^^^^^^^^^^^ method not found in `&std::sync::Mutex<Fallback_AD::EnzymeWrapper>`

For more information about this error, try `rustc --explain E0599`.
[RUSTC-TIMING] rustc_codegen_llvm test:false 2.923
error: could not compile `rustc_codegen_llvm` (lib) due to 11 previous errors
Bootstrap failed while executing `--stage 2 test --skip compiler --skip src`

@bjorn3
Copy link
Member

bjorn3 commented Nov 25, 2025

Do you have a backtrace?

@sgasho
Copy link
Contributor Author

sgasho commented Nov 25, 2025

I saw no further information using RUST_BACKTRACE=1
I executed these commands. any mistake?

RUST_BACKTRACE=1 ./x test --stage 1 tests/codegen-llvm/autodiff/scalar.rs

or

set RUST_BACKTRACE=1
./x test --stage 1 tests/codegen-llvm/autodiff/scalar.rs

@bjorn3
Copy link
Member

bjorn3 commented Nov 25, 2025

You will have to use a debugger. These are LLVM aborts, not rust panics, so RUST_BACKTRACE doesn't apply to them.

@sgasho
Copy link
Contributor Author

sgasho commented Nov 25, 2025

I see!
I installed CodeLLDB extension on my VS Code and created a debug settings, then got this trace
(Sorry I have no time to take at deeply look at it today, I'll check this later)

Launching: /Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/stage1/bin/rustc /Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/tests/codegen-llvm/autodiff/scalar.rs -Zthreads=1 -Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Ztranslate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/Users/suganoshota/.cargo -Z ignore-directory-in-diagnostics-source-blocks=/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/vendor --sysroot /Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/stage1 --target aarch64-apple-darwin --check-cfg cfg(test,FALSE) -O -Cdebug-assertions=no -Zcodegen-source-order --emit llvm-ir -o /Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/test/codegen-llvm/autodiff/scalar/scalar.ll -A internal_features -A unused_parens -A unused_braces -Crpath -Cdebuginfo=0 -Zautodiff=Enable,NoTT -C opt-level=3 -Clto=fat
Launched process 22915 from '/Volumes/WD_BLACK_SN850X_HS_1TB/rust-lang/rust/build/aarch64-apple-darwin/stage1/bin/rustc'
Assertion failed: (AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried"), function getResult, file PassManager.h, line 414.
Stop reason: hit program assert
thread backtrace all
  thread #1, name = 'main', queue = 'com.apple.main-thread'
    frame #0: 0x0000000186068ae4 libsystem_kernel.dylib`__ulock_wait + 8
    frame #1: 0x00000001860ac0ac libsystem_pthread.dylib`_pthread_join + 608
    frame #2: 0x0000000109051888 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::join at unix.rs:134:28 [opt]
    frame #3: 0x00000001063005c0 librustc_driver-1894da91bc51a45d.dylib`<std::thread::JoinInner<()>>::join + 32
    frame #4: 0x000000010630449c librustc_driver-1894da91bc51a45d.dylib`rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}> + 2292
    frame #5: 0x00000001062aa518 librustc_driver-1894da91bc51a45d.dylib`rustc_driver_impl::run_compiler + 4248
    frame #6: 0x00000001062b074c librustc_driver-1894da91bc51a45d.dylib`rustc_driver_impl::main + 208
    frame #7: 0x00000001000007b0 rustc`rustc_main::main + 12
    frame #8: 0x0000000100000764 rustc`std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()> + 12
    frame #9: 0x000000010000077c rustc`std::rt::lang_start::<()>::{closure#0} + 16
    frame #10: 0x0000000109046f94 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once at function.rs:287:21 [opt]
    frame #11: 0x0000000109046f8c librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panicking::catch_unwind::do_call at panicking.rs:590:40 [opt]
    frame #12: 0x0000000109046f88 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panicking::catch_unwind at panicking.rs:553:19 [opt]
    frame #13: 0x0000000109046f88 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panic::catch_unwind at panic.rs:359:14 [opt]
    frame #14: 0x0000000109046f88 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::rt::lang_start_internal::{{closure}} at rt.rs:175:24 [opt]
    frame #15: 0x0000000109046bb8 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panicking::catch_unwind::do_call at panicking.rs:590:40 [opt]
    frame #16: 0x0000000109046bb8 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panicking::catch_unwind at panicking.rs:553:19 [opt]
    frame #17: 0x0000000109046bb8 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal [inlined] std::panic::catch_unwind at panic.rs:359:14 [opt]
    frame #18: 0x0000000109046bb8 librustc_driver-1894da91bc51a45d.dylib`std::rt::lang_start_internal at rt.rs:171:5 [opt]
    frame #19: 0x00000001000007e4 rustc`main + 52
    frame #20: 0x0000000185ce1d54 dyld`start + 7184
  thread #2, name = 'ctrl-c'
    frame #0: 0x0000000186067908 libsystem_kernel.dylib`read + 8
    frame #1: 0x00000001062eac68 librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<ctrlc::set_handler_inner<rustc_driver_impl::install_ctrlc_handler::{closure#0}>::{closure#0}, ()> + 52
    frame #2: 0x00000001062feeec librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<ctrlc::set_handler_inner<rustc_driver_impl::install_ctrlc_handler::{closure#0}>::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 108
    frame #3: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #4: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #5: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136
  thread #3, name = 'rustc'
    frame #0: 0x0000000186066bb0 libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x0000000185eee990 libdispatch.dylib`_dispatch_sema4_wait + 28
    frame #2: 0x0000000185eeef40 libdispatch.dylib`_dispatch_semaphore_wait_slow + 132
    frame #3: 0x0000000109058d20 librustc_driver-1894da91bc51a45d.dylib`std::thread::Thread::park [inlined] std::sys::sync::thread_parking::darwin::Parker::park at darwin.rs:74:15 [opt]
    frame #4: 0x0000000109058d00 librustc_driver-1894da91bc51a45d.dylib`std::thread::Thread::park at mod.rs:1498:47 [opt]
    frame #5: 0x0000000107fc6308 librustc_driver-1894da91bc51a45d.dylib`<std::sync::mpmc::list::Channel<rustc_codegen_ssa::back::write::SharedEmitterMessage>>::recv::{closure#1} + 324
    frame #6: 0x0000000107fc6d10 librustc_driver-1894da91bc51a45d.dylib`<std::sync::mpmc::list::Channel<rustc_codegen_ssa::back::write::SharedEmitterMessage>>::recv + 372
    frame #7: 0x0000000107fa550c librustc_driver-1894da91bc51a45d.dylib`<rustc_codegen_ssa::back::write::SharedEmitterMain>::check + 152
    frame #8: 0x00000001065e5e98 librustc_driver-1894da91bc51a45d.dylib`<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::join_codegen + 168
    frame #9: 0x00000001064fc31c librustc_driver-1894da91bc51a45d.dylib`<rustc_interface::queries::Linker>::link + 304
    frame #10: 0x000000010630dd6c librustc_driver-1894da91bc51a45d.dylib`rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1} + 3524
    frame #11: 0x000000010630192c librustc_driver-1894da91bc51a45d.dylib`rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}> + 328
    frame #12: 0x00000001062eae1c librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> + 104
    frame #13: 0x00000001062ff1bc librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 268
    frame #14: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #15: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #16: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136
  thread #4
    frame #0: 0x000000018606a4f8 libsystem_kernel.dylib`__psynch_cvwait + 8
    frame #1: 0x00000001860aa0dc libsystem_pthread.dylib`_pthread_cond_wait + 984
    frame #2: 0x000000010902d680 librustc_driver-1894da91bc51a45d.dylib`<jobserver::HelperState>::for_each_request::<jobserver::imp::spawn_helper::{closure#1}::{closure#0}> + 256
    frame #3: 0x0000000109030620 librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<jobserver::imp::spawn_helper::{closure#1}, ()> + 36
    frame #4: 0x000000010902f91c librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<jobserver::imp::spawn_helper::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 160
    frame #5: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #6: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #7: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136
  thread #5
    frame #0: 0x000000018606a4f8 libsystem_kernel.dylib`__psynch_cvwait + 8
    frame #1: 0x00000001860aa0dc libsystem_pthread.dylib`_pthread_cond_wait + 984
    frame #2: 0x000000010902d680 librustc_driver-1894da91bc51a45d.dylib`<jobserver::HelperState>::for_each_request::<jobserver::imp::spawn_helper::{closure#1}::{closure#0}> + 256
    frame #3: 0x0000000109030620 librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<jobserver::imp::spawn_helper::{closure#1}, ()> + 36
    frame #4: 0x000000010902f91c librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<jobserver::imp::spawn_helper::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 160
    frame #5: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #6: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #7: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136
  thread #6, name = 'coordinator'
    frame #0: 0x0000000186066bb0 libsystem_kernel.dylib`semaphore_wait_trap + 8
    frame #1: 0x0000000185eee990 libdispatch.dylib`_dispatch_sema4_wait + 28
    frame #2: 0x0000000185eeef40 libdispatch.dylib`_dispatch_semaphore_wait_slow + 132
    frame #3: 0x0000000109058d20 librustc_driver-1894da91bc51a45d.dylib`std::thread::Thread::park [inlined] std::sys::sync::thread_parking::darwin::Parker::park at darwin.rs:74:15 [opt]
    frame #4: 0x0000000109058d00 librustc_driver-1894da91bc51a45d.dylib`std::thread::Thread::park at mod.rs:1498:47 [opt]
    frame #5: 0x000000010666a278 librustc_driver-1894da91bc51a45d.dylib`<std::sync::mpmc::list::Channel<rustc_codegen_ssa::back::write::Message<rustc_codegen_llvm::LlvmCodegenBackend>>>::recv::{closure#1} + 140
    frame #6: 0x000000010666b398 librustc_driver-1894da91bc51a45d.dylib`<std::sync::mpmc::list::Channel<rustc_codegen_ssa::back::write::Message<rustc_codegen_llvm::LlvmCodegenBackend>>>::recv + 460
    frame #7: 0x00000001065d921c librustc_driver-1894da91bc51a45d.dylib`rustc_codegen_ssa::back::write::start_executing_work::<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#4} + 1528
    frame #8: 0x00000001065d868c librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::start_executing_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#4}, core::result::Result<rustc_codegen_ssa::back::write::CompiledModules, ()>>::{closure#0}, core::result::Result<rustc_codegen_ssa::back::write::CompiledModules, ()>> + 72
    frame #9: 0x00000001065df85c librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::start_executing_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#4}, core::result::Result<rustc_codegen_ssa::back::write::CompiledModules, ()>>::{closure#0}, core::result::Result<rustc_codegen_ssa::back::write::CompiledModules, ()>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 472
    frame #10: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #11: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #12: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136
* thread #7, name = 'opt cgu.0', stop reason = hit program assert
  * frame #0: 0x000000018606f5b0 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001860a9888 libsystem_pthread.dylib`pthread_kill + 296
    frame #2: 0x0000000185fae850 libsystem_c.dylib`abort + 124
    frame #3: 0x0000000185fada84 libsystem_c.dylib`__assert_rtn + 284
    frame #4: 0x00000001057ed734 libEnzyme-21.dylib`TypeAnalyzer::TypeAnalyzer(FnTypeInfo const&, TypeAnalysis&, unsigned char) + 3960
    frame #5: 0x00000001058267fc libEnzyme-21.dylib`TypeAnalysis::analyzeFunction(FnTypeInfo const&) + 288
    frame #6: 0x000000010568fa5c libEnzyme-21.dylib`(anonymous namespace)::EnzymeBase::HandleAutoDiff(llvm::Instruction*, unsigned int, llvm::Value*, llvm::Type*, llvm::SmallVectorImpl<llvm::Value*>&, std::__1::map<int, llvm::Type*, std::__1::less<int>, std::__1::allocator<std::__1::pair<int const, llvm::Type*>>> const&, std::__1::vector<DIFFE_TYPE, std::__1::allocator<DIFFE_TYPE>> const&, llvm::Function*, DerivativeMode, (anonymous namespace)::EnzymeBase::Options&, bool, llvm::SmallVectorImpl<llvm::CallInst*>&) + 1580
    frame #7: 0x000000010568a0a0 libEnzyme-21.dylib`(anonymous namespace)::EnzymeBase::HandleAutoDiffArguments(llvm::CallInst*, DerivativeMode, bool, llvm::SmallVectorImpl<llvm::CallInst*>&) + 644
    frame #8: 0x00000001056856d8 libEnzyme-21.dylib`(anonymous namespace)::EnzymeBase::lowerEnzymeCalls(llvm::Function&, std::__1::set<llvm::Function*, std::__1::less<llvm::Function*>, std::__1::allocator<llvm::Function*>>&) + 13188
    frame #9: 0x0000000105680974 libEnzyme-21.dylib`(anonymous namespace)::EnzymeBase::run(llvm::Module&) + 1384
    frame #10: 0x000000010569e6bc libEnzyme-21.dylib`llvm::detail::PassModel<llvm::Module, EnzymeNewPM, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 28
    frame #11: 0x000000011816727c libLLVM.dylib`llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 328
    frame #12: 0x00000001066f9888 librustc_driver-1894da91bc51a45d.dylib`LLVMRustOptimize + 10124
    frame #13: 0x000000010667a720 librustc_driver-1894da91bc51a45d.dylib`rustc_codegen_llvm::back::write::llvm_optimize + 3500
    frame #14: 0x000000010667e1d0 librustc_driver-1894da91bc51a45d.dylib`rustc_codegen_llvm::back::write::optimize + 508
    frame #15: 0x00000001065d7060 librustc_driver-1894da91bc51a45d.dylib`rustc_codegen_ssa::back::write::execute_optimize_work_item::<rustc_codegen_llvm::LlvmCodegenBackend> + 140
    frame #16: 0x00000001065d7e8c librustc_driver-1894da91bc51a45d.dylib`std::sys::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()> + 180
    frame #17: 0x00000001065df1a8 librustc_driver-1894da91bc51a45d.dylib`<<std::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 212
    frame #18: 0x0000000109051578 librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start [inlined] <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once at boxed.rs:2005:9 [opt]
    frame #19: 0x000000010905156c librustc_driver-1894da91bc51a45d.dylib`std::sys::thread::unix::Thread::new::thread_start at unix.rs:126:17 [opt]
    frame #20: 0x00000001860a9c08 libsystem_pthread.dylib`_pthread_start + 136

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 25, 2025

Good that you properly solved the first bug. I had just commented it out back in my PR and then ended up running into the same bug you're seeing now as well "This analysis pass was not registered prior to being queried". I found it weird, since an earlier dlopen version in my PR had worked, it was only during the cleanup that it broke, so it's not necessary a bug on the LLVM side, we just use it wrong . Still, if you end up building LLVM in debug mode to run gdb on it, be warned that the build will be huge, 100-130GB probably.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Nov 25, 2025

To be more clear at what did (not) work. In my first attempt where I just dlopen'ed Enzyme directly in compiler/rustc_codegen_llvm/src/back/write.rs and immediately passed it to llvm::LLVMRustOptimize it worked. When I tried to clean up the code and store the registerEnzymeAndPassPipeline behind a mutex and load it later, that's when I started seeing this bug. Just if you want to experiment around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants